﻿/*
 * Copyright 2014 Francois Karman
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

using Quartz.WebManager.Logic;
using Quartz.WebManager.Model;
using System.Collections.Generic;
using System.Web.Http;

namespace Quartz.WebManager.Web.ApiControllers
{
    /// <summary>
    /// Defines the API that provides the list of the available job definitions.
    /// </summary>
    [RoutePrefix("api/job-definitions")]
    public class JobDefinitionController : ApiController
    {
        /// <summary>
        /// Gets all the known jobs.
        /// </summary>
        /// <returns>The list of known jobs.</returns>
        [Route("")]
        [HttpGet]
        public IEnumerable<JobDefinition> GetAll()
        {
            return JobDefinitionManager.Cache;
        }

        /// <summary>
        /// Refreshes the list of known jobs.
        /// </summary>
        [Route("refresh")]
        [HttpGet]
        public IEnumerable<JobDefinition> Refresh()
        {
            JobDefinitionManager.Refresh();
            return JobDefinitionManager.Cache;
        }
    }
}
